home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 1 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: engnews2.Eng.Sun.COM!lupa!corbett
  2. From: corbett@lupa.eng.sun.com (Robert Corbett)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Circular buffering for FILEs?  Why not?
  5. Date: 2 Jan 1996 01:25:40 GMT
  6. Organization: Sun Microsystems Computer Corporation
  7. Message-ID: <4ca1ik$ffa@engnews2.Eng.Sun.COM>
  8. References: <4c9i65$3b6@segfault.monkeys.com> <4c9q8e$63i@access2.digex.net>
  9. NNTP-Posting-Host: lupa.eng.sun.com
  10. Cc: 
  11.  
  12. In article <4c9q8e$63i@access2.digex.net>,
  13. John Cochran <jdc@access2.digex.net> wrote:
  14. >In article <4c9i65$3b6@segfault.monkeys.com>,
  15. >Ronald F. Guilmette <rfg@monkeys.com> wrote:
  16. >>I have a question about the traditional implementation of buffered FILEs.
  17. >>
  18. >>From this fact I deduce that traditional implementations of the entire
  19. >>stdio set of functions _do not_ treat FILE buffers as so-called ``circular
  20. >>buffers'' but rather treat them a mere linear buffers.
  21. >>
  22. >>My question is just this... Why?
  23. >>
  24. >>Given that traditional implementations of the FILE structure include a
  25. >>``_cnt'' field, it seems to me that it would have been possible... albeit
  26. >>at a slight cost... to treat FILE buffers as circular buffers, wraping
  27. >>the value of _ptr back to the physical beginning of the buffer each time
  28. >>it was seen to have passed the physical end of the buffer.  But it seems
  29. >>that nobody does this.  Why not?
  30. >
  31. >Why bother?
  32.  
  33. "Why bother" is the correct answer.  The reasons given (which I have
  34. deleted) are correct, but not complete.  A higher-level explanation
  35. might prove helpful.  Circular buffering is useful when I/O and
  36. processing can be overlapped.  Circular buffering allows sequential I/O
  37. to read ahead or write behind while the data already read is being
  38. processed or the next batch of data to be written is being computed.
  39. Since C has no notion of overlapped I/O and processing, circular
  40. buffering not useful in implementing the C I/O library.  The underlying
  41. OS might support overlapped I/O and processing.  The OS, therefore,
  42. might well be using circular buffers when dealing with sequential
  43. devices.  For direct access devices, the popular buffering schemes
  44. tend to be more complex than circular buffering.
  45.  
  46.                     Sincerely,
  47.                     Bob Corbett
  48.